<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .con{
            height:30px;
            width:500px;
            margin:0px auto;
            background:#eee;
        }
        .pg{
            height:30px;
            background:red;
            width:100px;
        }
    </style>
</head>
<body>
    <div class="con">
        <div class="pg" id="pg" style="width:0;"></div>
    </div>
    <button id="start">开始</button>
    <button id="pause">暂停</button>
</body>
<script>
    var con=document.getElementById("con");
    var pg=document.getElementById("pg");
    var start=document.getElementById("start");
    var pause=document.getElementById("pause");
    var intervalId;
    start.onclick=function(){
        intervalId=setInterval(function(){
            var width=pg.style.width;

            width=parseInt(width)+1;
            pg.style.width=width+"px";
            if(width==500){
                clearInternval(intervalId);
            }
        },50)
        pause.onclick=function(){
            clearInterval(intervalId);
        }
    }
    
</script>
</html>